<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../react/react17.development.js"></script>
    <script src="../react/react-dom17.development.js"></script>
    <script src="../react/babel.min.js"></script>
    <script src="../react/axios.js"></script>
</head>

<body>
    <div id="main"></div>
    <script type="text/babel">
        class List extends React.Component {
            render() {
                let { item } = this.props;
                return (<li>
                    <span>{item.period}</span>
                    <span>{item.spercialty}</span>
                    <span>{item.squad}</span>
                    <span>{item.age}</span>
                    <span>{item.username}</span>
                    <span>{item.phone}</span>
                </li>)
            }
        }
        class Com extends React.Component {
            state = {
                arr: [],
                pages: [1, 2, 3, 4, 5]
            }
            pageClick(p) {
                console.log(p);
                axios.get("http:localhost:3000/homeList", {
                    params: {  //get请求传递给服务端的数据
                        page: p
                    }
                })
                    .then((res) => {
                        console.log(res.data.data);
                        this.setState({
                            arr: res.data.data
                        })
                    })
            }
            render() {
                let { arr, pages } = this.state;
                return (<div>
                    <ul>
                        {arr.map((item, index) => (<List item={item} key={index} />))}
                    </ul>
                    <ol>
                        {pages.map((item, index) => (<li key={index} onClick={this.pageClick.bind(this, item)}>{item}</li>))}
                    </ol>
                </div>)
            }
            componentDidMount() {
                this.pageClick(1);
            }
        }

        ReactDOM.render(<Com />, document.getElementById("main"));
    </script>
</body>

</html>